import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/home/home_controller.dart';
import 'package:flutter_changdian_football/pages/mine/user_store.dart';
import 'package:flutter_changdian_football/routers/app_routes.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/get.dart';

// 选择城市和消息数量
class AddressAndMsgWidget extends StatelessWidget {
  const AddressAndMsgWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeController>(
      builder: (homeController) {
        return Stack(
          children: [
            Image.asset(
              'assets/images/img_nav_bg.png',
              fit: BoxFit.fitWidth,
              width: double.infinity,
            ),

            Positioned(
              bottom: 13.w,
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 16.w),
                width: MediaQuery.of(context).size.width,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        homeController.changeDefaultLocation();
                      },
                      child: Row(
                        children: [
                          SizedBox(
                            width: 14.w,
                            height: 17.w,
                            child: Image.asset('assets/images/icon_nav_dw.png'),
                          ),
                          SizedBox(width: 4.w,),
                          SizedBox(
                            child: Text('${homeController.locationModel?.district}', style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.normal, color: const Color(0xff333333))),
                          ),
                          Icon(
                            Icons.arrow_drop_down,
                            size: 20.w,
                          ),
                        ],
                      ),
                    ),

                    GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        if (UserStore.to.checkLoginPage()) {
                          Get.toNamed(AppRoutes.message);
                        }
                      },
                      child: Stack(
                        clipBehavior: Clip.none,
                        children: [
                          SizedBox(
                            width: 22.w,
                            height: 22.w,
                            child: Image.asset('assets/images/home_msg.png'),
                          ),
                          if ((homeController.indexPageBaseInfoModel?.waitReadMessageNum ?? 0) > 0) ...[
                            Positioned(
                              top: -4,
                              right: -4,
                              child: Offstage(
                                offstage: false,
                                child: Container(
                                  width: 15.w,
                                  height: 15.w,
                                  decoration: const ShapeDecoration(
                                    shape: CircleBorder(),
                                    color: Colors.red,
                                  ),
                                  alignment: Alignment.center,
                                  child: Text('${homeController.indexPageBaseInfoModel?.waitReadMessageNum ?? 0}', style: TextStyle(fontSize: 8.sp, color: Colors.white),),
                                ),
                              )
                            ),
                          ]
                          
                        ],
                      ),
                    )
                  ],
                ),
              )
            )
          ],
        );
      }
    );
  }
}